package com.xiaoq.sites.endpoint;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import com.xiaoq.coms.GenericListResponse;
import com.xiaoq.sites.entity.LegendEntity;
import com.xiaoq.sites.service.ILegendService;
import com.xiaoq.sites.vo.LegendVo;

@RestController
@RequestMapping("/api/v1/sites_infra/legend")
public class LegendEndpoint {
	
	@Autowired
	private ILegendService legendSer;
	
	private static final class LegendListResponse extends GenericListResponse<LegendVo>{};
	
	private Logger logger = LoggerFactory.getLogger(LegendEndpoint.class);
	
	@ApiOperation(value="图例列表", notes="图例列表")
	@ApiResponses({
		@ApiResponse(code = 200, response = LegendListResponse.class, message = "图例列表")
	})
	@GetMapping(value="/", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> sitesBusStationBySites() {
		List<LegendEntity> legendList = legendSer.legendList();
		List<LegendVo> legendVoList = new ArrayList<>();
		LegendVo legendVo = null;
		if(CollectionUtils.isNotEmpty(legendList)){
			for(LegendEntity legend:legendList){
				legendVo = new LegendVo();
				BeanUtils.copyProperties(legend, legendVo);
				legendVoList.add(legendVo);
			}
		}else{
			logger.info("查询结果为空！");
		}
		return LegendListResponse.listNoCount(legendVoList);
		
	}
	
}
